import { getInstance } from '@/utils/hook-util'
import { BaseType } from '@/components/base/form-item/props'
import { getCurrentInstance } from 'vue'
import { DrawerProps } from '@/components/base/base-drawer/BaseDrawer.vue'
export interface TableHook {
  /**
   * 请求表格数据方法
   * @param params
   */
  requestPage: (params?: BaseType) => void
  /**
   * 刷新
   */
  refresh: () => void
}
/**
 * 表格hooks
 * @param refName 表格refs名称
 * @param drawerProps 抽屉属性
 */
export const useTable = (refName = 'baseTable'): TableHook => {
  const instance = getCurrentInstance()
  return {
    requestPage(params?: BaseType) {
      const hook = getInstance<TableHook>(refName, instance)
      hook.requestPage(params)
    },
    refresh() {
      const hook = getInstance<TableHook>(refName, instance)
      hook.requestPage({ pageNum: 1, pageSize: 10 })
    },
  }
}
